package com.ljpz.sso.query.controller;

import com.ljpz.sso.query.api.UserQueryService;
import com.ljpz.sso.query.bean.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Created by liujunchen on 2017/1/16.
 */
@RequestMapping("user")
@Controller
public class UserController {
    @Autowired
    private UserQueryService userQueryService   ;
    /**
     * 根据token信息查询用户信息
     *
     *
     */
    @RequestMapping(value ="{token}",method = RequestMethod.GET)
    public ResponseEntity<User>queryUserByToken(@PathVariable("token") String token ){
        try {
        User  user  = this.userQueryService.queryUserByToken(token)  ;

            if (null==user){
                return  ResponseEntity.status(HttpStatus.NOT_FOUND).body(null)  ;
            }
            return  ResponseEntity.ok(user)  ;
        } catch (Exception e) {
                e.printStackTrace();
        }
        return   ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null) ;
    }

}
